﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace AspNetCoreWeb.Mvc.Filters
{
    /// <summary>
    /// TypeFilter就是因为它并不需要在依赖注入容器里注册类型就能创建出过滤器
    /// </summary>
    public class SaveLastActivityAttribute : TypeFilterAttribute
    {
        /// <summary>
        /// Create instance of the filter attribute
        /// </summary>
        public SaveLastActivityAttribute() : base(typeof(SaveLastActivityFilter))
        {
        }
        private class SaveLastActivityFilter : IActionFilter
        {
            private readonly ILogger<SaveLastActivityFilter> _logger;
            public SaveLastActivityFilter(ILogger<SaveLastActivityFilter> logger)
            {
                this._logger = logger;
            }
            public void OnActionExecuting(ActionExecutingContext context)
            {

                _logger.LogInformation("OnActionExecuting");
            }

            public void OnActionExecuted(ActionExecutedContext context)
            {
                _logger.LogInformation("OnActionExecuted");
            }
        }
    }
}
